/*************************************************************************
 *
 * definice a inicializace globalnich dat
 * 
 * (c) Ales Povalac, alpov@alpov.net, http://www.alpov.net/
 * 
 *************************************************************************
 *
 * $Id: data.c 33 2006-07-01 09:19:05Z alpov $
 * 
 *************************************************************************/         

#include <stdint.h>
#include <avr/pgmspace.h>
#include "../avrx/avrx.h"
#include "../avrx/AvrXFifo.h"
#include "data.h"
#include "menu_lcd.h"

Mutex DataLock;


INTERNAL_DATA_DESCRIPTOR EEPROM eeprom = {
    .sensor_index = 0,
    .id = 100,
    .contrast = 50
};

INTERNAL_DATA_DESCRIPTOR idata;

SHARED_DATA_DESCRIPTOR sdata = {
    .sensor_desc = {
        "Prvni",
        "Druhy",
        "Posledni",
        "nic1",
        "nic2",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
    },
    .temperature = {253, -106, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    .sensor_count = 3,
    
    .mode_desc = {
        "Rezim jedna",
        "rezim dva",
        "Posledni rezim",
        "nic1",
        "nic2",
        "",
        "",
        ""
    },
    .mode_count = 3,
    .mode = 1,

    .shift = -10,
    .shift_length = 12,
    
    .sw_mode = 2,
    .sw_datetime = 212954400,
    
    .now = 181418400       
};


/*************************************************************************
 * nacteni internich promennych z eeprom
 *************************************************************************/ 
void ReadEepromData(void)
{
    idata.id = AvrXReadEEProm(&eeprom.id);
    idata.contrast = AvrXReadEEProm(&eeprom.contrast);
    LcdSetContrast(idata.contrast);
}


/*************************************************************************
 * zapis internich promennych do eeprom
 *************************************************************************/ 
void WriteEepromData(void)
{
    AvrXWriteEEProm(&eeprom.id, idata.id);
    AvrXWriteEEProm(&eeprom.contrast, idata.contrast);
}

